#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/Swap.h>
#pragma unmanaged 
#include <ql\instruments\cpiswap.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ICPISwap
	public ref class CCPISwap  : 
            public CSwap,
            public Cephei::QL::Instruments::ICPISwap
	{
	protected: 
		boost::shared_ptr<QuantLib::CPISwap>* _ppCPISwap;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CPISwap>* _phCPISwap;
#endif
		Object^ _CPISwapOwner;     // reference to object that manages the storage for this object
	internal:
		CCPISwap (QL::Instruments::CPISwap::TypeEnum type, Double nominal, Boolean subtractInflationNominal, Double spread, Cephei::QL::Times::IDayCounter^ floatDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, QL::Times::BusinessDayConventionEnum floatRoll, UInt32 fixingDays, Cephei::QL::Indexes::IIborIndex^ floatIndex, Double fixedRate, Double baseCPI, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ fixedSchedule, QL::Times::BusinessDayConventionEnum fixedRoll, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Indexes::IZeroInflationIndex^ fixedIndex, Microsoft::FSharp::Core::FSharpOption<QL::Cashflows::CPI::InterpolationTypeEnum>^ observationInterpolation, Microsoft::FSharp::Core::FSharpOption<Double>^ inflationNominal, Cephei::QL::IPricingEngine^ QL_Pricer);
        CCPISwap (boost::shared_ptr<QuantLib::CPISwap>& childNative, Object^ owner);
        CCPISwap (QuantLib::CPISwap& childNative, Object^ owner);
        CCPISwap (CCPISwap^ copy);
        CCPISwap (PLATFORM::Type^ t);
#ifdef STRUCT
        CCPISwap (QuantLib::CPISwap childNative);
#endif       
#ifdef HANDLE
		CCPISwap (QuantLib::Handle<QuantLib::CPISwap>& childNative, Object^ owner);
		CCPISwap (QuantLib::Handle<QuantLib::CPISwap> childNative);
#endif
		virtual ~CCPISwap ();
		!CCPISwap ();

	internal:
		QuantLib::CPISwap& GetReference ();
		boost::shared_ptr<QuantLib::CPISwap>& GetShared ();
		QuantLib::CPISwap* GetPointer ();
        void SetCPISwap (boost::shared_ptr<QuantLib::CPISwap> native)
        {
            if (_ppCPISwap != NULL)
                delete _ppCPISwap;
            _ppCPISwap = new boost::shared_ptr<QuantLib::CPISwap> (native);
            SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CPISwap>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Double BaseCPI 
        {
		    virtual Double get () ;
        }
        property Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ CpiLeg 
        {
		    virtual Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Double FairRate 
        {
		    virtual Double get () ;
        }
        property Double FairSpread 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Times::IDayCounter^ FixedDayCount 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property Cephei::QL::Indexes::IZeroInflationIndex^ FixedIndex 
        {
		    virtual Cephei::QL::Indexes::IZeroInflationIndex^ get () ;
        }
        property Double FixedLegNPV 
        {
		    virtual Double get () ;
        }
        property QL::Times::BusinessDayConventionEnum FixedPaymentRoll 
        {
		    virtual QL::Times::BusinessDayConventionEnum get () ;
        }
        property Double FixedRate 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Times::ISchedule^ FixedSchedule 
        {
		    virtual Cephei::QL::Times::ISchedule^ get () ;
        }
        property UInt32 FixingDays 
        {
		    virtual UInt32 get () ;
        }
        property Cephei::QL::Times::IDayCounter^ FloatDayCount 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property Cephei::QL::Indexes::IIborIndex^ FloatIndex 
        {
		    virtual Cephei::QL::Indexes::IIborIndex^ get () ;
        }
        property Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ FloatLeg 
        {
		    virtual Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Double FloatLegNPV 
        {
		    virtual Double get () ;
        }
        property QL::Times::BusinessDayConventionEnum FloatPaymentRoll 
        {
		    virtual QL::Times::BusinessDayConventionEnum get () ;
        }
        property Cephei::QL::Times::ISchedule^ FloatSchedule 
        {
		    virtual Cephei::QL::Times::ISchedule^ get () ;
        }
        property Double InflationNominal 
        {
		    virtual Double get () ;
        }
        property Double Nominal 
        {
		    virtual Double get () ;
        }
        property QL::Cashflows::CPI::InterpolationTypeEnum ObservationInterpolation 
        {
		    virtual QL::Cashflows::CPI::InterpolationTypeEnum get () ;
        }
        property Cephei::QL::Times::IPeriod^ ObservationLag 
        {
		    virtual Cephei::QL::Times::IPeriod^ get () ;
        }
        property Double Spread 
        {
		    virtual Double get () ;
        }
        property Boolean SubtractInflationNominal 
        {
		    virtual Boolean get () ;
        }
        property QL::Instruments::CPISwap::TypeEnum Type 
        {
		    virtual QL::Instruments::CPISwap::TypeEnum get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Instruments::ICPISwap^>::typeid)]
	[FactoryFor(Cephei::QL::Instruments::ICPISwap::typeid)]
	[FactoryFor(Cephei::QL::Instruments::ICPISwap_Factory::typeid)]
	public ref class CCPISwap_Factory sealed : public ICPISwap_Factory
	{
	public:
        virtual ICPISwap^ Create (QL::Instruments::CPISwap::TypeEnum type, Double nominal, Boolean subtractInflationNominal, Double spread, Cephei::QL::Times::IDayCounter^ floatDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, QL::Times::BusinessDayConventionEnum floatRoll, UInt32 fixingDays, Cephei::QL::Indexes::IIborIndex^ floatIndex, Double fixedRate, Double baseCPI, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ fixedSchedule, QL::Times::BusinessDayConventionEnum fixedRoll, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Indexes::IZeroInflationIndex^ fixedIndex, Microsoft::FSharp::Core::FSharpOption<QL::Cashflows::CPI::InterpolationTypeEnum>^ observationInterpolation, Microsoft::FSharp::Core::FSharpOption<Double>^ inflationNominal, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
